package de.jmda.gen.java.impl;

import javax.validation.constraints.NotNull;

import de.jmda.gen.java.CompilationUnitPackageGenerator;
import de.jmda.gen.java.DeclaredElementGenerator;
import de.jmda.gen.java.DeclaredPackageGenerator;

/**
 * @author roger.jmda@gmail.com
 */
public class DefaultCompilationUnitPackageGenerator
		extends AbstractDeclarationGenerator
		implements CompilationUnitPackageGenerator
{
	@NotNull
	private DeclaredPackageGenerator generator;

	public DefaultCompilationUnitPackageGenerator()
  {
		this(new DefaultDeclaredPackageGenerator());
  }

	/**
	 * @param generator
	 */
	public DefaultCompilationUnitPackageGenerator(
			@NotNull DeclaredPackageGenerator generator)
  {
	  super();
	  
	  setDeclaredPackageGenerator(notNull(generator));

	  setComponentSeparator(System.lineSeparator());
  }

	@Override
  public DeclaredPackageGenerator getDeclaredPackageGenerator()
  {
		return generator;
  }

	@Override
  public void setDeclaredPackageGenerator(
  		@NotNull DeclaredPackageGenerator generator)
  {
		if (generator == null)
		{
			return;
		}

		this.generator = generator;
  }

	@Override
  public DeclaredElementGenerator getDeclaredElementGenerator()
  {
	  return getDeclaredPackageGenerator();
  }

	private DeclaredPackageGenerator notNull(DeclaredPackageGenerator generator)
  {
		if (generator == null)
		{
			generator = new DefaultDeclaredPackageGenerator();
		}

		return generator;
  }
}